import threading,time
def decrement(n):
    while n > 0:
        n -= 1
if __name__ == '__main__':
    start = time.time()
    decrement(50000000)
    decrement(50000000)
    cost = time.time() - start
    print("单个主线程耗时",cost)
    start = time.time()
    t1 = threading.Thread(target=decrement, args=[50000000])
    t2 = threading.Thread(target=decrement, args=[50000000])
    t1.start()  # 启动线程，执行任务
    t2.start()  # 同上
    t1.join()  # 主线程阻塞，直到t1执行完成，主线程继续往后执行
    t2.join()  # 同上
    cost = time.time() - start
    print("多个线程耗时", cost)
    """
    单个主线程耗时
    3.875006914138794
    多个线程耗时
    3.306212902069092(理论上应该是2秒左右)
    """

